#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<unistd.h>

int main(int argc, char const *argv[])
{
    int fd = open("test.txt", O_RDONLY | O_CREAT, 0666);
    if(fd == -1){
        perror("open failed\n");
        return -1;
    }
    long file_size1 = 0;
    char ch[1];
    while(1){
        int read_size = read(fd, ch, 1);
        if(read_size < 0){
            perror("read failed\n");
            return -1;
        }
        if(read_size == 0){
            printf("read end\n");
            break;
        }
        if(read_size > 0)file_size1++;
    }
    close(fd);

    int fd2 = open("test.txt", O_RDONLY);
    if(fd2 == -1){
        perror("open failed\n");
        return -1;
    }
    lseek(fd2, 0, SEEK_END);
    long file_size2 = lseek(fd2, 0, SEEK_CUR);
    lseek(fd2, 0, SEEK_CUR);
    close(fd2);

    printf("file size is %ld\n", file_size1);
    printf("file size is %ld\n", file_size2);
    return 0;
}
